﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace Data
{
    public class PaisDataAccess
    {
        private SQLiteConnection con = DataBaseHelper.GetConnection("BDHostal.sqlite");
        private bool exitoRegistrar;
        DataSet dataSet = new DataSet();
        DataTable dt = new DataTable();
        public bool agregarNuevoPais(string nombrePais)
        {
            using (var cmd = con.CreateCommand())
            {
                try
                {
                    con.Open();
                    cmd.CommandText = "INSERT INTO paises(nombrePais) VALUES ('" + nombrePais.ToLowerInvariant() + "')";
                    cmd.ExecuteNonQuery();
                    exitoRegistrar = true;

                }
                catch (SQLiteException ex)
                {

                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    exitoRegistrar = false;
                }
                finally
                {
                    cmd.Dispose();
                    con.Close();
                }
            }
            return exitoRegistrar;
        }
        public DataTable buscarPaises()
        {
            string cmd = "SELECT * FROM paises";
            {
                try
                {
                    con.Open();
                    SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(cmd, con);
                    dataSet.Reset();
                    dataAdapter.Fill(dataSet);
                    dt = dataSet.Tables[0];
                }
                catch (SystemException ex)
                {
                }
                finally
                {
                    con.Close();
                }
            }
            return dt;
        }
    }
}
